package com.example.base.tools.upgrade

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import com.example.base.vm.BaseViewModel

class DownloadViewModel(
    savedStateHandle: SavedStateHandle
) : BaseViewModel<DownloadRepository>(savedStateHandle) {

    override fun createRepository() = DownloadRepository()

    /*fun downloadNewVersionAPK(downloadInfo: DownloadInfo, downloadListener: DownloadListener?) {
        viewModelScope.launch {
            try {
                com.villaday.orticketroom.repository.downloadInfo = downloadInfo
                com.villaday.orticketroom.repository.downloadListener = downloadListener
                com.villaday.orticketroom.repository.downloadNewVersionAPK()
            } catch (t: Throwable) {
                t.printStackTrace()
                cancel()
            }
        }
    }*/

    fun downloadNewVersionAPK(downloadInfo: DownloadInfo, downloadListener: DownloadListener?) =
        Launch {
            repository.downloadInfo = downloadInfo
            repository.downloadListener = downloadListener
            repository.downloadNewVersionAPK()
        }

}